package com.providerticket.controller;

import com.providerticket.bean.JsonDate;
import com.providerticket.entity.SysUserEntity;
import com.providerticket.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Dylan Yang
 * @Title: SysUserController
 * @ProjectName demo
 * @Description: TODO
 * @date 2018/10/117:04
 */
@RestController
@RequestMapping(value = "/sysUser/")
public class SysUserController {

    @Autowired
    private SysUserService userService;

    /**
     * 查询所有用户
     */
    @GetMapping(value ="queryUserAll" )
    public JsonDate queryUserAll() {
        List<SysUserEntity> userEntityList = userService.queryUserAll();
        if (userEntityList.size() > 0){
            return new JsonDate(200,"success",userEntityList);
        }
        return new JsonDate(500,"error","系统内部错误，请稍后再试！");
    }

    /**
     *  根据名字进行查询
     */
    @GetMapping(value = "findByUserName")
    public JsonDate findByUserName(String userName){
        SysUserEntity userEntity = userService.findByUserName("admin");
        if (userEntity != null){
            return new JsonDate(200,"success",userEntity);
        }
        return new JsonDate(500,"error","系统内部错误，请稍后再试！");
    }
}

